<table id="admin_adminInfo_data"></table>
<script>
	$(function(){
		$('#admin_adminInfo_data').datagrid({
			url:'../adminUserServlet',
			queryParams:{op:"getAdminUser"},
			loadMsg:'数据加载中...',
			fitColumns:true,
			pagination:true,
			rownumbers:true,
			sortName:'aid',
			sortOrder:'asc',
			remoteSort:true,
			pageNumber:1,
			pageSize:10,
			pageList:[10,20,30,40,50],
			beforePageText:'第',
			afterPageText:'页  共{pages}页',
			displayMsg:'当前显示{from}-{to} 条记录 共{total} 条记录',
			columns:[[
				{field:'pwd',title:'',checkbox:true,width:100,align:'center'},
				{field:'aid',title:'管理员编号',width:100,align:'center'},   
		        {field:'aname',title:'管理员姓名',width:90,align:'center'},  
		        {field:'pwds',title:'管理员密码',width:200,align:'center'}, 
		        {field:'tel',title:'联系电话',width:100,align:'center'}, 
				{field:'email',title:'邮箱',width:140,align:'center'},
				{field:'statuss',title:'状态',width:100,align:'center'}  
			]],
			toolbar:[{
				text:'添加',
				iconCls: 'icon-add',
				handler: function(){
					$("#admin_adminInfo_data_add").dialog("open");//显示添加信息对话框
				}
			},'-',{
				text:'删除',
				iconCls: 'icon-remove',
				handler: function(){
					//获取选中的行
					var rows=$("#admin_adminInfo_data").datagrid("getChecked");
					if(rows<=0){
						$.messager.show({
							title:'温馨提示',
							msg:'请选择您要删除的数据...',
							timeout:2000,
							showType:'slide'
						});
					}else{
						$.messager.confirm('信息确认', '您确定要删除选中的记录吗?', function(r){
							if (r){
								var aids="";
								//获取所有选中数据的id
								for(var i=0;i<rows.length-1;i++){
									aids+=rows[i].aid+",";
								}
								aids+=rows[i].aid;
								
								//向服务器发送请求
								$.post("../adminUserServlet?t="+new Date(),{op:"delAdminUser",aids:aids},function(data){
									data=parseInt( $.trim(data) );
									if(data>0){
										$.messager.show({
											title:'成功提示',
											msg:'管理员信息删除成功...',
											timeout:2000,
											showType:'slide'
										});
										$("#admin_adminName").val("");
										$("#admin_adminPwd").val("");
										$("#admin_adminInfo_data_add").dialog("close");
										$("#admin_adminInfo_data").datagrid("reload")
									}else{
										$.messager.alert('失败提示','管理员信息删除失败，请稍后重试..','error');
									}
								});
							}
						});
					}
				}
			},'-',{
				text:'修改',
				iconCls: 'icon-edit',
				handler:function(){
					var rows=$("#admin_adminInfo_data").datagrid('getChecked');
					if(rows.length<=0){
						$.messager.show({title:'温馨提示',msg:'请选择您要修改的数据...',timeout:2000,showType:'slide'});
					}else{
						$("#admin_adminName_update").val( rows[0].aname );
						$("#admin_adminPwd_update").val( rows[0].pwd );
						$("#admin_adminTel_update").val( rows[0].tel );
						$("#admin_adminEmail_update").val( rows[0].email );
						$("#admin_adminAid_update").val( rows[0].aid );
						$("#admin_adminInfo_data_update").dialog("open");
					} 
				}
			}]
		});
	})
	
	$("#admin_adminInfo_data").datagrid('getPager').pagination({
		beforePageText:'第',
		afterPageText:'页  共{pages}页',
		displayMsg:'当前显示{from}-{to} 条记录 共{total} 条记录'
	});
	
	//添加管理员信息
	function admin_addInfo(){
		var aname=$.trim( $("#admin_adminName").val() );
		var pwd=$.trim( $("#admin_adminPwd").val() );
		var tel=$.trim( $("#admin_adminTel").val() );
		var email=$.trim( $("#admin_adminEmail").val() );
		
		//为空判断
		if(aname!="" && pwd!=""){
			$.post("../adminUserServlet?t="+new Date(),{op:"addAdminUser",aname:aname,pwd:pwd,tel:tel,email:email},function(data){
				data=parseInt( $.trim(data) );
				if(data>0){
					$.messager.show({
						title:'成功提示',
						msg:'管理员信息添加成功...',
						timeout:3000,
						showType:'slide'
					});
					$("#admin_adminName").val("");
					$("#admin_adminPwd").val("");
					$("#admin_adminInfo_data_add").dialog("close");
					$("#admin_adminInfo_data").datagrid("reload")
				}else{
					$.messager.alert('失败提示','管理员信息添加失败，请稍后重试..','error');
				}
			});
		}else{
			$.messager.show({
				title:'温馨提示',
				msg:'您输入的信息不完整，请确认后再提交...',
				timeout:3000,
				showType:'slide'
			});
		}
	}
	
	//修改管理员信息
	function admin_updateInfo(){
		var aname=$.trim( $("#admin_adminName_update").val() );
		var pwd=$.trim( $("#admin_adminPwd_update").val() );
		var tel=$.trim( $("#admin_adminTel_update").val() );
		var email=$.trim( $("#admin_adminEmail_update").val() );
		var aid=$.trim( $("#admin_adminAid_update").val() );
		$.post("../adminUserServlet?t="+new Date(),{op:"updateAdminUser",aname:aname,pwd:pwd,tel:tel,email:email,aid:aid},function(data){
			data=parseInt( $.trim(data) );
			if(data>0){
				$.messager.show({
					title:'成功提示',
					msg:'管理员信息修改成功...',
					timeout:3000,
					showType:'slide'
				});
				$("#admin_adminName_update").val("");
				$("#admin_adminPwd_update").val("");
				$("#admin_adminAid_update").val("");
				$("#admin_adminInfo_data_update").dialog("close");//关闭对话框
				$('#admin_adminInfo_data').datagrid("reload");
			}else{
				$.messager.alert('失败提示','管理员信息修改失败，请稍后重试..','error');
			}
		});
	}
</script>

<div id="admin_adminInfo_data_add" class="easyui-dialog" title="添加管理员信息" style="width:400px;height:260px;" 
		data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<br><br>
	<center>
		<label for="admin_adminName">管理员姓名：</label><input type="text" id="admin_adminName" /><br><br>
		<label for="admin_adminPwd">管理员密码：</label><input type="password" id="admin_adminPwd" /><br><br>
		<label for="admin_adminPwd">联系方式：</label><input type="text" id="admin_adminTel" /><br><br>
		<label for="admin_adminPwd">邮箱帐号：</label><input type="text" id="admin_adminEmail" /><br><br>
		<input type="button" onClick="admin_addInfo()" value="添加" />
	</center>
</div>

<div id="admin_adminInfo_data_update" class="easyui-dialog" title="修改管理员信息" style="width:400px;height:260px;" 
		data-options='iconCls:"icon-edit",resizable:true,modal:true,closed:true'>
	<br><br>
	<input type="hidden" id="admin_adminAid_update" />
	<center>
		<label for="admin_adminName_update">管理员姓名：</label><input type="text" id="admin_adminName_update" /><br><br>
		<label for="admin_adminPwd_update">管理员密码：</label><input type="password" id="admin_adminPwd_update" /><br><br>
		<label for="admin_adminPwd_update">联系方式：</label><input type="text" id="admin_adminTel_update" /><br><br>
		<label for="admin_adminPwd_update">邮箱帐号：</label><input type="text" id="admin_adminEmail_update" /><br><br>
		<input type="button" onClick="admin_updateInfo()" value="修改" />
	</center>
</div>